package com.itranswarp.learnjava;

/**
 * Learn Java from https://www.liaoxuefeng.com/
 * 
 * @author liaoxuefeng
 */
public class Main {

	public static void main(String[] args) { try {
        String token = login("admin", "pass");
        System.out.println("Token: " + token);
    }catch (LoginFailedException e1){
        e1.printStackTrace();
        System.out.println("测试失败：登陆异常");
    }catch (UserNotFoundException e2){
        e2.printStackTrace();
        System.out.println("测试失败：用户名异常");
    }finally {
        System.out.println("Finally：测试结束！");
    }
	}

	static String login(String username, String password) {
		if (username.equals("admin")) {
			if (password.equals("password")) {
				return "测试成功";
			} else {
				// 抛出LoginFailedException:
				throw new LoginFailedException("Bad username or password.");
			}
		} else {
			// 抛出UserNotFoundException:
			throw new UserNotFoundException("User not found.");
		}
	}
	
	
}
